﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using DevComponents.DotNetBar;
using DTO;
using BUS;

namespace QLST
{
    public partial class frmMain : Form
    {
        
        public frmMain()
        {
            InitializeComponent();
            //frmFlash m_FrmFlash = new frmFlash();
            //m_FrmFlash.Show();
            //System.Threading.Thread.Sleep(3000);
            //m_FrmFlash.Close();
        }
        public string pass = "", user="";
        //DoiMatKhauDTO dm;
        private void frmMain_Load(object sender, EventArgs e)
        {
            frmDangNhap frm = new frmDangNhap();
            frm.ShowDialog();
            Defaul(false);


            pass = frm.password.ToString();
            user = frm.username.ToString();
            if (frm.flag ==true )
            {
                if (frm.loaiNV.ToString() == "NVQT")
                {
                    Defaul(true);
                    lbThongBao.Text = "Xin Chào admin! " + frm.username.ToString();
                }
                else if ( frm.loaiNV.ToString ()=="NVPP")
                {
                    btnFDangNhap.Enabled = false ;
                    btnFDangXuat.Enabled = true;
                    btnFDoiMatKhau.Enabled = true;
                    QuanLy.Enabled = true;
                    ThongKe.Enabled = true;
                    QuyDinh.Enabled = true;
                    TroGiup.Enabled = true;
                    btnKho.Enabled = true;
                    btnQuay.Enabled = true;
                    lbThongBao.Text = "Xin Chào nhân viên! " + frm.username.ToString();
                }
                else if(frm.loaiNV .ToString ()=="NVQL")
                {
                    btnFDangNhap.Enabled = false;
                    btnFDangXuat.Enabled = true;
                    btnFDoiMatKhau.Enabled = true;
                    QuanLy.Enabled = true;
                    ThongKe.Enabled = true;
                    QuyDinh.Enabled = true;
                    TroGiup.Enabled = true;
                    btnKho.Enabled = true;
                    btnQuay.Enabled = true;
                    btnThemSanPham.Enabled = true;
                    lbThongBao.Text = "Xin Chào nhân viên! " + frm.username.ToString();
                }
                else if(frm.loaiNV.ToString ()=="NVTH")
                {
                    btnFDangNhap.Enabled = false;
                    btnFDangXuat.Enabled = true;
                    btnFDoiMatKhau.Enabled = true;
                    QuanLy.Enabled = true;
                    QuyDinh.Enabled = true;
                    TroGiup.Enabled = true;
                    btnQuyen.Enabled = true;
                    btnPhanQuyen.Enabled = true;
                    btnPhanNhomNguoiDung.Enabled = true;
                    btnPhanNhom.Enabled = true;
                    lbThongBao.Text = "Xin Chào nhân viên! " + frm.username.ToString();
                }
                else if (frm.loaiNV.ToString() == "NVTN")
                {
                    btnFDangNhap.Enabled = false;
                    btnFDangXuat.Enabled = true;
                    btnFDoiMatKhau.Enabled = true;
                    QuanLy.Enabled = true;
                    QuyDinh.Enabled = true;
                    TroGiup.Enabled = true;
                    btnKhachHang.Enabled = true;
                    btnHoaDon.Enabled = true;
                    lbThongBao.Text = "Xin Chào nhân viên! " + frm.username.ToString();
                }

 
            }
            else
            {
                Defaul(false);
            }
           
        }


        #region xử lý các nút trong file

        private void btnFDangNhap_Click(object sender, EventArgs e)
        {
            frmMain_Load(sender, e);
        }

        private void btnFDangXuat_Click(object sender, EventArgs e)
        {
            Defaul(false );
        }

        private void btnFDoiMatKhau_Click(object sender, EventArgs e)
        {
<<<<<<< .mine
         
            frmDoiMatKhau frm=new frmDoiMatKhau();
            frm.Sender(user, pass);
=======
            //dm.User = user ;
            //dm.Pass = pass ;
            frmDoiMatKhau frm=new frmDoiMatKhau();
>>>>>>> .r27
            frm.ShowDialog ();
        }

        private void btnFBackup_Click(object sender, EventArgs e)
        {
            frmBackup_Restore frm = new frmBackup_Restore();
            frm.rdSaoLuu.Checked = true;
            frm.ShowDialog();
        }

        private void btnFRestore_Click(object sender, EventArgs e)
        {
            frmBackup_Restore frm = new frmBackup_Restore();
            frm.rdPhucHoi.Checked = true;
            frm.ShowDialog();
        }

        private void btnFThoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        #endregion

        #region default
        public void Defaul(Boolean f)
        {
            btnFBackup.Enabled = f;
            btnFDangXuat.Enabled = f;
            btnFDoiMatKhau.Enabled = f;
            btnFRestore.Enabled = f;
            QuanLy.Enabled = f;
            ThongKe.Enabled = f;
            QuyDinh.Enabled = f;
            btnFDangNhap.Enabled = !f;
            //-----
            btnThemSanPham.Enabled = f;
            btnHoaDon.Enabled = f;
            btnKho.Enabled = f;
            btnQuay.Enabled = f;
            btnNhanVien.Enabled = f;
            btnKhachHang.Enabled = f;
            btnPhanNhom.Enabled = f;
            btnPhanQuyen.Enabled = f;
            btnQuyen.Enabled = f;
            btnPhanNhomNguoiDung.Enabled = f;

            lbThongBao.Text  = "Đăng nhập hệ thống để sử dụng chương trình!";
        }
        #endregion

        #region xử lý nút quản lý
        private void btnHoaDon_Click(object sender, EventArgs e)
        {
            frmHoaDon frm = new frmHoaDon();
            frm.ShowDialog();
        }

        private void btnKhachHang_Click(object sender, EventArgs e)
        {
            frmKhachHang frm = new frmKhachHang ();
            frm.ShowDialog();
        }

        private void btnKho_Click(object sender, EventArgs e)
        {
            frmKho frm = new frmKho();
            frm.ShowDialog();
        }

        private void btnQuay_Click(object sender, EventArgs e)
        {
            frmQuay frm = new frmQuay();
            frm.ShowDialog();
        }

        private void btnNhanVien_Click(object sender, EventArgs e)
        {
            frmNhanVien frm = new frmNhanVien();
            frm.ShowDialog();
        }

        private void btnThemSanPham_Click(object sender, EventArgs e)
        {
            
            frmSanPham frm = new frmSanPham();
            frm.ShowDialog();
        }

        private void btnPhanQuyen_Click(object sender, EventArgs e)
        {
            frmPhanQuyen frm = new frmPhanQuyen();
            frm.ShowDialog();
        }

        private void btnQuyen_Click(object sender, EventArgs e)
        {
            frmQuyen frm = new frmQuyen();
            frm.ShowDialog();
        }

        private void btnPhanNhom_Click(object sender, EventArgs e)
        {
            frmPhanNhom frm = new frmPhanNhom();
            frm.ShowDialog();
        }

        private void btnPhanNhomNguoiDung_Click(object sender, EventArgs e)
        {
            frmNhomNguoiDung frm = new frmNhomNguoiDung();
            frm.ShowDialog();
        }

        #endregion

       
        #region thống kê

        #endregion


        #region Qui định Siêu thị

        #endregion


        #region trợ giúp

        private void btnTroGiup_Click(object sender, EventArgs e)
        {

        }

        private void btnMayTinh_Click(object sender, EventArgs e)
        {
            Process.Start("calc.exe");
        }

        private void btnPhanMem_Click(object sender, EventArgs e)
        {
            frmThongTinPhanMem frm = new frmThongTinPhanMem();
            frm.ShowDialog();
        }
        #endregion


        #region chua có xử lý

        #endregion

    }
}
